<template>
	<div class="outerFrame">
		<div class="search">
			<el-form ref="form" :inline="true" :model="request" label-width="80px">
				<el-form-item label="合约">
				    <el-select v-model="request.param.type" placeholder="请选择">
				      <el-option label="已签约" value="1"></el-option>
				      <el-option label="未签约" value="2"></el-option>
				    </el-select>
				  </el-form-item>
				  
				<el-form-item label="">
					<el-checkbox-group v-model="checkgq">
				      <el-checkbox v-model="checkgq" label="查看已过期" name="endtime"></el-checkbox>
					  </el-checkbox-group>
			  </el-form-item>
				 
				<el-form-item label="企业名称"><el-input v-model="request.param.ename"></el-input></el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
					<el-button @click="clearSearchVal">清空</el-button>
				</el-form-item>
			</el-form>
		</div>
		<div class="operator">
			<el-button type="primary" icon="el-icon-plus" @click="toSave()" v-hasPermission="'003000000000'">添加</el-button>
		</div>
		<div class="dataTable" v-if="listData">
			<el-table :data="listData" stripe border height="85%" v-loading="listLoading" @selection-change="selectionChange" style="text-align: center;">
						<el-table-column type="index" width="50" label="序号"></el-table-column>
						<el-table-column prop="ename" label="企业名称"></el-table-column>
						<el-table-column prop="signtm" label="签约时间"
						:formatter="
							(row, column) => {
								return row.signtm != null ? row.signtm : '未签约';
							}
						"
						></el-table-column>
						<el-table-column prop="begintime" label="送餐开始"></el-table-column>
						<el-table-column prop="endtime" label="送餐结束"></el-table-column>
						<el-table-column prop="std" label="餐标"
						:formatter="
							(row, column) => {
								return row.std != null ? row.std : '-';
							}
						"
						></el-table-column>
						
						<el-table-column prop="interval" label="送餐时段"></el-table-column>
						<el-table-column prop="cuttime" label="截单时间"></el-table-column>
						
						<el-table-column prop="address" label="地址"></el-table-column>
						<el-table-column prop="phone" label="电话"
							:formatter="
								(row, column) => {
									return row.phone != null ? (row.phone.slice(0,3)+'-'+row.phone.slice(3,12)):'-';
								}
							"
						></el-table-column>
						
						<el-table-column prop="empcnt" label="规模"
						:formatter="
							(row, column) => {
								return row.empcnt != null ? row.empcnt : '-';
							}
						"></el-table-column>
						
						<el-table-column prop="code" label="企业码"></el-table-column>
						<el-table-column prop="sendcost" label="配送费"
						:formatter="
							(row, column) => {
								return row.sendcost != null ? row.sendcost:'-';
							}
						"
						></el-table-column>
						
				<el-table-column label="操作" fixed="right" width="400px">
					<template slot-scope="scope">
						<div class="dataTable-operator">
							<el-button size="mini" icon="el-icon-view" type="info" @click="toView(scope.$index, scope.row)" v-hasPermission="'003000010000'">查看</el-button>
							<el-button size="mini" icon="el-icon-edit" @click="toUpdate(scope.$index, scope.row)" v-hasPermission="'003000010000'">修改</el-button>
							<el-button size="mini" icon="el-icon-edit" @click="toMenber(scope.$index, scope.row)" v-hasPermission="'003000020000'">成员管理</el-button>
							<el-button size="mini" type="danger" icon="el-icon-delete" @click="remove(scope.$index, scope.row)" v-hasPermission="'003000030000'">删除</el-button>
						</div>
					</template>
				</el-table-column>
			</el-table>
			
		</div>
		<editDialog :parameter="editParameter" :isDisplay.sync="editDisplay"></editDialog>
		<viewDialog :parameter="editParameter" :isDisplay.sync="viewDisplay"></viewDialog>
		 <menberDialog :parameter="editParameter" :isDisplay.sync="menberDisplay"></menberDialog>
	</div>
</template>
<script>

import utils from 'util/utils.js';
import constant from 'util/constant.js';
import api from 'api/crm/enterprise/enterprise.js';
import editDialog from './edit.vue';
import viewDialog from './view.vue';
import menberDialog from './menberlist.vue';

export default {
	name: 'enterprise',
	data() {
		return {
			checkgq: false,
			
			listLoading: true,
			listData: [],
			editDisplay: false,
			viewDisplay: false,
			menberDisplay: false,
			editParameter: {},
			constant: constant,
			request: utils.newRequest()
		};
	},
	components: {
		editDialog,
		viewDialog,
		menberDialog
	},
	methods: {
		//改变选择项
		selectionChange(val) {
			//清空
			this.request.param.ids = [];
			for (let item of val) {
				this.request.param.ids.push(item.id);
			}
		},
		//获取数据
		list() {
			this.listLoading = true;
			api.list(this.request, response => {
				// console.log(response.data)
				this.listData = response.data;
				this.listLoading = false;
			});
		},
		//去添加
		toSave() {
			this.editDisplay = true;
			this.editParameter = {};
		},
		//去编辑
		toUpdate(index, row) {
			this.editDisplay = true;
			this.editParameter = {
				id: row.id
			};
		},
		toView(index, row) {
			this.viewDisplay = true;
			this.editParameter = {
				id: row.id
			};
		},
		toMenber(index, row) {
			this.menberDisplay = true;
			this.editParameter = {
				id: row.id
			};
		},
		//删除
		remove(index, row) {
			//单个删除
			if (row) {
				this.request.param.ids = [row.id];
			}
			if (!this.request.param.ids || this.request.param.ids.length == 0) {
				utils.msg.info('请选择至少一行');
				return;
			}
			utils.confirm('确定删除吗？', '提示', () => {
				api.remove(
					this.request,
					response => {
						utils.msg.success(response.msg);
						this.list();
					},
					response => {
						utils.msg.warning(response.msg);
					}
				);
			});
		},
		//搜索
		search() {
			if (this.checkgq) {
				var date = new Date();
				var Y = date.getFullYear() + '-';
				var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) +'-';
				var D = date.getDate() +'';
				this.request.param.endtime = Y+M+D;
			}else{
				this.request.param.endtime = null;
			}
			this.list();
		},
		//清空搜索框
		clearSearchVal() {
			this.checkgq = false;
			this.request.param = {};
		}
	},
	mounted() {
		this.list();
	}
};
</script>

<style lang="scss">
@import '~common/custom/css/common.scss';
</style>
